package mushystuff.dtb.web.components;

import java.util.SortedSet;

import mushystuff.dtb.core.model.Product;
import mushystuff.dtb.core.model.Sprint;
import mushystuff.dtb.core.model.UserStory;
import mushystuff.dtb.core.service.ProductService;

import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

@SuppressWarnings("unused")
@IncludeJavaScriptLibrary({"${tapestry.scriptaculous}/dragdrop.js"})
public class SprintBacklogList {
    
    @Parameter(allowNull=false, required=true)
    @Property
    private Sprint sprint;
    
    @Property
    private UserStory userStory;
    
    @Environmental
    private RenderSupport renderSupport;
    
    @SetupRender
    void init() {
        renderSupport.addScript("$('sprintBacklog_" + sprint.getId() + "').select('li').each( function(li) {new Draggable(li, { revert: true, handle: 'handle' });});");
        renderSupport.addScript("Droppables.add('sprintBacklog_" + sprint.getId() + "', {onDrop: function(draggable, droppable, event) { droppable.appendChild(draggable); }});");
    }

}
